package com.zhb86.live.ui;

import android.os.Bundle;
import android.view.Gravity;
import android.view.MenuItem;
import android.view.View;
import android.widget.GridLayout;
import android.widget.Toast;

import com.google.android.material.navigation.NavigationView;
import com.superyee.commonlib.entity.DataListResponse;
import com.superyee.commonlib.ui.BaseActivity;
import com.zhb86.live.R;
import com.zhb86.live.adapter.LiveGridAdapter;

import java.util.ArrayList;
import java.util.List;

import androidx.annotation.NonNull;
import androidx.drawerlayout.widget.DrawerLayout;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.lifecycle.Lifecycle;
import androidx.lifecycle.LifecycleObserver;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.viewpager2.adapter.FragmentStateAdapter;
import androidx.viewpager2.widget.ViewPager2;

public class LivePlayerHomeActiviy extends BaseActivity {
    private  ArrayList<Fragment> fragmentArrayList=new ArrayList<>();
    private View mHeaderView;
    @Override
    protected int getLayoutId() {
        return R.layout.live_player_home;
    }

    @Override
    protected void initPerData(Bundle savedInstanceState) {

    }

    @Override
    protected void initView() {
       ViewPager2 viewPager2= findViewById(R.id.viewPager);
       DrawerLayout drawerLayout= findViewById(R.id.drawerLayout);
        NavigationView mNavView= findViewById(R.id.navigationView);
        mNavView.setItemIconTintList( null );
        fragmentArrayList.add(LivePlayerFragment.newInstance("1"));
        fragmentArrayList.add(LivePlayerFragment.newInstance("1"));
        fragmentArrayList.add(LivePlayerFragment.newInstance("1"));
        fragmentArrayList.add(LivePlayerFragment.newInstance("1"));
        Lifecycle ll=new Lifecycle() {
            @Override
            public void addObserver(@NonNull LifecycleObserver observer) {

            }

            @Override
            public void removeObserver(@NonNull LifecycleObserver observer) {

            }

            @NonNull
            @Override
            public State getCurrentState() {
                return null;
            }
        };
       InnerPagerAdapter adapter=new InnerPagerAdapter(getSupportFragmentManager(), ll,fragmentArrayList);
       viewPager2.setAdapter(adapter);
       viewPager2.setCurrentItem(1);

        mNavView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
            @Override
            public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) {
                Toast.makeText(LivePlayerHomeActiviy.this, "1111", Toast.LENGTH_SHORT).show();
                //mNavView.closeDrawers();
                return true;
            }
        });
        findViewById(R.id.tv_more).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                drawerLayout.openDrawer(Gravity.RIGHT);
            }
        });

         mHeaderView= mNavView.getHeaderView(0);
         RecyclerView recyclerView=mHeaderView.findViewById(R.id.recyclerview);
         GridLayoutManager layoutManager = new GridLayoutManager(this, 2);
         recyclerView.setLayoutManager(layoutManager);
         List<Object> list=new ArrayList<>();
         list.add(new Object());list.add(new Object());
         list.add(new Object());list.add(new Object());list.add(new Object());list.add(new Object());

         LiveGridAdapter mAdapter=new LiveGridAdapter(R.layout.live_recycler_content,list);
         mAdapter.bindToRecyclerView(recyclerView);

    }

    @Override
    public void onPointerCaptureChanged(boolean hasCapture) {

    }


    @Override
    protected void initData() {

    }

    @Override
    protected void addListener() {

    }

    @Override
    protected void removeListener() {

    }

    @Override
    public void onReceiverNotify(int action, Object obj, int statusCode) {

    }


    private class InnerPagerAdapter extends FragmentStateAdapter {
       private  ArrayList<Fragment> fragments = new ArrayList();

       public InnerPagerAdapter(@NonNull FragmentManager fragmentManager, @NonNull Lifecycle lifecycle,ArrayList<Fragment> fragments) {
           super(fragmentManager, lifecycle);
           this.fragments=fragments;
       }


       @NonNull
       @Override
       public Fragment createFragment(int position) {
           return fragments.get(position);
       }

       @Override
       public int getItemCount() {
           return fragments.size();
       }
   }
}
